home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Techy Stuff / Development Environments ƒ / Perl 4.0.2 ƒ / missing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-19  |  3.5 KB  |  220 lines

  1. /* $Header: missing.c $
  2.  *
  3.  *    Copyright (c) 1991, 1992 Matthias Neeracher
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  */
  9.  
  10. #define SystemSevenOrLater    1
  11. #define RESOLVE_MAC_CONFLICTS
  12.  
  13. #include "EXTERN.h"
  14. #include "perl.h"
  15. #include <Events.h>
  16.  
  17. /* Calls that don't exist on the mac */
  18.  
  19. /* Borrowed from msdos.c
  20.  * Just pretend that everyone is a superuser
  21.  */
  22. #define ROOT_UID    0
  23. #define ROOT_GID    0
  24. int
  25. getuid(void)
  26. {
  27.     return ROOT_UID;
  28. }
  29.  
  30. int
  31. geteuid(void)
  32. {
  33.     return ROOT_UID;
  34. }
  35.  
  36. int
  37. getgid(void)
  38. {
  39.     return ROOT_GID;
  40. }
  41.  
  42. int
  43. getegid(void)
  44. {
  45.     return ROOT_GID;
  46. }
  47.  
  48. int
  49. setuid(int uid)
  50. { return (uid==ROOT_UID?0:-1); }
  51.  
  52. int
  53. setgid(int gid)
  54. { return (gid==ROOT_GID?0:-1); }
  55.  
  56. execv()
  57. {
  58.     fatal("execv() not implemented on the Macintosh");
  59. }
  60.  
  61. execvp()
  62. {
  63.     fatal("execvp() not implemented on the Macintosh");
  64. }
  65.  
  66. utime()
  67. {
  68.     fatal("utime() not implemented on the Macintosh");
  69. }
  70.  
  71. chmod()
  72. {
  73. }
  74.  
  75. kill()
  76. {
  77.     fatal("kill() not implemented on the Macintosh");
  78. }
  79.  
  80. sleep(int seconds)
  81. {
  82.     long    ticks    =    TickCount() + seconds*60;
  83.     
  84.     while (TickCount() < ticks)
  85.         SpinPerlCursor(1);
  86. }
  87.  
  88. do_aspawn()
  89. {
  90.     fatal("do_aspawn() not implemented on the Macintosh");
  91. }
  92.  
  93. do_spawn()
  94. {
  95.     fatal("do_spawn() not implemented on the Macintosh");
  96. }
  97.  
  98. char **environ;
  99.  
  100. init_env(char ** env)
  101. {
  102.     int        envcnt    =    0;
  103.     int        envsize    =    0;
  104.     int        varlen;
  105.     char    *    envpool;
  106.     
  107.     for (envcnt = 0; env[envcnt]; envcnt++)    {
  108.         varlen    = strlen(env[envcnt]);
  109.         envsize    +=    varlen+strlen(env[envcnt]+varlen+1)+2;
  110.     }
  111.     
  112.     environ = (char **)     malloc((envcnt+1)*sizeof(char *));
  113.     envpool = (char *)     malloc(envsize);
  114.     
  115.     for (envcnt = 0; env[envcnt]; envcnt++)    {
  116.         environ[envcnt]     = envpool;
  117.         varlen                = strlen(env[envcnt]);
  118.         strcpy(envpool, env[envcnt]);
  119.         envpool              += varlen+1;
  120.         envpool[-1]            = '=';
  121.         strcpy(envpool, env[envcnt]+varlen+1);
  122.         envpool              += strlen(env[envcnt]+varlen+1)+1;
  123.     }
  124.     
  125.     environ[envcnt] = 0;
  126. }    
  127.  
  128. typedef struct PD {
  129.     struct PD *    next;
  130.     FILE *        tempFile;
  131.     FSSpec        pipeFile;
  132.     char *        execute;
  133. } PipeDescr, *PipeDescrPtr;
  134.  
  135. static PipeDescrPtr    pipes        =    nil;
  136. static Boolean            sweeper    =    false;
  137.  
  138. void sweep()
  139. {
  140.     while (pipes)
  141.         mypclose(pipes->tempFile);
  142. }
  143.  
  144. FILE * mypopen(char * command, char * mode)
  145. {
  146.     PipeDescrPtr    pipe;
  147.     
  148.     New(666, pipe, 1, PipeDescr);
  149.     
  150.     if (!pipe)
  151.         return NULL;
  152.         
  153.     if (FSpMakeTempFile(&pipe->pipeFile))
  154.         goto failed;
  155.     pipe->execute    =    nil;
  156.     
  157.     switch(*mode)    {
  158.     case 'r':
  159.         if (SubLaunch(command, nil, &pipe->pipeFile, nil))
  160.             goto delete;
  161.         if (!(pipe->tempFile    = fopen(FSp2FullPath(&pipe->pipeFile), "r")))
  162.             goto delete;
  163.         break;
  164.     case 'w':
  165.         New(667, pipe->execute, strlen(command)+1, char);
  166.         if (!pipe->execute ||╩!(pipe->tempFile    = fopen(FSp2FullPath(&pipe->pipeFile), "w")))
  167.             goto delete;
  168.         strcpy(pipe->execute, command);
  169.         break;
  170.     }
  171.     
  172.     pipe->next    =    pipes;
  173.     pipes            =    pipe;
  174.     
  175.     if (!sweeper)    {
  176.         atexit(sweep);
  177.         sweeper    =    true;
  178.     }
  179.  
  180.     return pipe->tempFile;
  181. delete:
  182.     if (pipe->execute)
  183.         Safefree(pipe->execute);
  184.     FSpDelete(&pipe->pipeFile);
  185. failed:
  186.     Safefree(pipe);
  187.     
  188.     return NULL;
  189. }
  190.  
  191. int mypclose(FILE *    f)
  192. {
  193.     OSErr                err;
  194.     PipeDescrPtr *    prev;
  195.     PipeDescrPtr    pipe;
  196.     
  197.     for (prev = (PipeDescrPtr *) &pipes; pipe = *prev; prev = &pipe->next)
  198.         if (pipe->tempFile == f)
  199.             break;
  200.     
  201.     if (!pipe)
  202.         return -1;
  203.     
  204.     *prev = pipe->next;
  205.     
  206.     fclose(f);
  207.     
  208.     if (pipe->execute)
  209.         err = SubLaunch(pipe->execute, &pipe->pipeFile, nil, nil);
  210.     else
  211.         err = noErr;
  212.         
  213.     FSpDelete(&pipe->pipeFile);
  214.     if (pipe->execute)
  215.         Safefree(pipe->execute);
  216.     Safefree(pipe);
  217.     
  218.     return err?-1:0;    
  219. }
  220.